package com.yuezhi.consumer.config.Publish_Subscribe;

import com.yuezhi.consumer.constant.QueueConstant;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 发布订阅模式
 * Fanout交换机配置
 */
@Configuration
public class RabbitFanoutConfig {

    @Bean
    Queue fanoutOne() {
        return new Queue(QueueConstant.FANOUT_QUEUE_ONE);
    }

    @Bean
    Queue fanoutTwo() {
        return new Queue(QueueConstant.FANOUT_QUEUE_TWO);
    }

    @Bean
    FanoutExchange fanoutExchange() {
        return new FanoutExchange(QueueConstant.FANOUT_EXCHANGE, true , false);
    }

    @Bean
    Binding bindingOne() {
        return BindingBuilder.bind(fanoutOne()).to(fanoutExchange());
    }

    @Bean
    Binding bindingTwo() {
        return BindingBuilder.bind(fanoutTwo()).to(fanoutExchange());
    }
}
